<?php

declare(strict_types=1);

namespace App\Controller\Client;


use App\Amqp\DelayProducer;
use App\Amqp\Producer\NoticeCertificationCompanyProducer;
use App\Constants\ErrorCode;
use App\Controller\AbstractController;
use App\Dao\AdminUserDao;
use App\Exception\BusinessException;
use App\Request\Client\Common\DiscoverRequest;
use App\Request\Client\Common\UploadImageRequest;
use App\Service\Client\CommonService;
use App\Utils\Captcha;
use App\Utils\LevelRule;
use App\Utils\Log;
use Hyperf\Di\Annotation\Inject;

class CommonController extends AbstractController
{
    /**
     * @Inject()
     * @var CommonService
     */
    protected $commonService;

    /**
     * 获取客服电话
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function servicePhone()
    {
        $data = $this->commonService->servicePhone();
        return $this->response->success($data);
    }


    /**
     * 任务类型
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function taskType()
    {
        $data = $this->commonService->taskType();
        return $this->response->success($data);
    }

    public function levelRule()
    {
        return $this->response->success(LevelRule::text());
    }

    /**
     * banner列表
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function banner()
    {
        $data = $this->commonService->banner();
        return $this->response->success($data);
    }

    /**
     * 发现页
     * @param DiscoverRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function discover(DiscoverRequest $request)
    {
        $validator = $request->validated();
        $data = $this->commonService->discover($validator);
        return $this->response->success($data);
    }

    /**
     * 抽成比例
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function commissionPercent()
    {
        $data = $this->commonService->commissionPercent();
        return $this->response->success($data);
    }


    /**
     * @param UploadImageRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Throwable
     */
    public function uploadImage(UploadImageRequest $request)
    {
        $validator = $request->validated();
        $data = $this->commonService->uploadImage($validator);
        return $this->response->success($data);
    }



    /**
     * @Inject()
     * @var AdminUserDao
     */
    protected $adminUserDao;

    public function tt()
    {
        try {
            var_dump(1);
            $this->tt2();
            var_dump(3);
        }catch (\Throwable $e){
            var_dump(5);
            throw new BusinessException(22222);
        }
    }

    public function tt2()
    {
        try {
            var_dump(2);
            throw new \Exception('11','22');
        }catch (\Throwable $e){
            var_dump([$e->getCode(),$e->getMessage()]);
            var_dump(4);
            throw new BusinessException(1111);
        }
    }
}